using System;
using System.Collections.Generic;
using UnityEngine;
using com.amazon.device.iap.cpt;

public class AmazonIAPV2Manager : MonoBehaviour
{
	public static AmazonIAPV2Manager instance;

	private IAmazonIapV2 iapService = AmazonIapV2Impl.Instance;

	public static string successful = "successful";

	public static event Action<GetUserDataResponse> amazonGetUserDataResponse;

	public static event Action<PurchaseResponse> amazonPurchaseResponse;

	public static event Action<GetProductDataResponse> amazonGetProductDataResponse;

	public static event Action<GetPurchaseUpdatesResponse> amazonGetPurchaseUpdatesResponse;

	private void Awake()
	{
		instance = this;
	}

	private void OnEnable()
	{
	}

	private void OnDestroy()
	{
		instance = null;
	}

	public void Init()
	{
		RequestOutput userData = iapService.GetUserData();
		string requestId = userData.RequestId;
		BCWDebug.Log("Init In App Amazone RequestId:  " + requestId, "InApp");
	}

	private void EventInit(GetUserDataResponse arg)
	{
		BCWDebug.LogError("Event Init  ", "InApp");
		if (AmazonIAPV2Manager.amazonGetUserDataResponse != null)
		{
			BCWDebug.LogError("Event Init 2  ", "InApp");
			AmazonIAPV2Manager.amazonGetUserDataResponse(arg);
		}
	}

	public void PurchaseItem(string idItem)
	{
		SkuInput skuInput = new SkuInput();
		skuInput.Sku = idItem;
		RequestOutput requestOutput = iapService.Purchase(skuInput);
		BCWDebug.Log("PurchaseItemAmazon RequestId:  " + requestOutput.RequestId, "InApp");
	}

	private void EventPurchaseResponce(PurchaseResponse arg)
	{
		BCWDebug.LogError("Event PurchaseResponce  ", "InApp");
		if (AmazonIAPV2Manager.amazonPurchaseResponse != null)
		{
			BCWDebug.LogError("Event PurchaseResponce 2 ", "InApp");
			AmazonIAPV2Manager.amazonPurchaseResponse(arg);
		}
	}

	public void InitiatePurchase(List<string> listPurchases)
	{
		SkusInput skusInput = new SkusInput();
		skusInput.Skus = listPurchases;
		RequestOutput productData = iapService.GetProductData(skusInput);
		string requestId = productData.RequestId;
		BCWDebug.Log("Get Product Data RequestId:  " + productData.RequestId, "InApp");
	}

	private void EventGetProductDataResponse(GetProductDataResponse arg)
	{
		BCWDebug.LogError("Event GetProductDataResponse  ", "InApp");
		if (AmazonIAPV2Manager.amazonGetProductDataResponse != null)
		{
			BCWDebug.LogError("Event GetProductDataResponse  2", "InApp");
			AmazonIAPV2Manager.amazonGetProductDataResponse(arg);
		}
	}

	public void NotifyFulfillment(string receiptId)
	{
		NotifyFulfillmentInput notifyFulfillmentInput = new NotifyFulfillmentInput();
		notifyFulfillmentInput.ReceiptId = receiptId;
		notifyFulfillmentInput.FulfillmentResult = "FULFILLED";
		BCWDebug.Log("Send Successful NotifyFulfillment  ", "InApp");
		iapService.NotifyFulfillment(notifyFulfillmentInput);
	}

	public void GetPurchaseUpdate()
	{
		ResetInput resetInput = new ResetInput();
		resetInput.Reset = true;
		RequestOutput purchaseUpdates = iapService.GetPurchaseUpdates(resetInput);
		BCWDebug.Log("Get Purchase Update RequestId:  " + purchaseUpdates.RequestId, "InApp");
	}

	private void EventGetPurchaseUpdate(GetPurchaseUpdatesResponse arg)
	{
		BCWDebug.LogError("EventGetPurchaseUpdate  ", "InApp");
		if (AmazonIAPV2Manager.amazonGetPurchaseUpdatesResponse != null)
		{
			BCWDebug.LogError("EventGetPurchaseUpdate  2 ", "InApp");
			AmazonIAPV2Manager.amazonGetPurchaseUpdatesResponse(arg);
		}
	}
}
